<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 1、
      const obj = {
        message: "hello",
        getMessage() {
          const message = "abc";
          return this.message;
        },
      };
      console.log(obj.getMessage()); //谁调用就指向谁
      // 2、
      const obj1 = {
        message: "hello",
        logMws() {
          console.log(this);
          console.log(this.message);
        },
      };
      setTimeout(() => {
        console.log(this); //window
        obj1.logMws();  //obj1
      }, 1000);

      // 3、
      const object = {
        who: "world",
        get() {
          return `hello, ${this.who}`; //world
        },
        far: () => {
          return `goodbye, ${this.who}`; //window
        },
      };
      console.log(object.get());
      console.log(object.far());

      // 4、
      var length = 4;
      function callback() {
        console.log(this.length);
      }
      const object2 = {
        length: 5,
        method(callback) {
          callback();
        },
      };
      object2.method(callback);  //window

      // 5、
      // var length = 4;
      // function callback2() {
      //   console.log(this);
      // }
      // const object3 = {
      //   length: 5,
      //   method2() {
      //     arguments[0](); //arguments函数内置的对象，可以实时拿到传进来的实参
      //   },
      // };
      // object3.method2(callback2, 4, 5, 7, 8, 9); //arguments.length
    </script>
  </body>
</html>
